﻿<?php
    //新闻分类添加
    ob_clean();
    $id=empty($_GET['id'])?0:$_GET['id'];
    $sql = "select * from `cate` where `pid`=$id";
    $result =mysqli_query($link,$sql);
    $data = array();//最终存储新闻表的所有数据数组
    while ($row = mysqli_fetch_assoc($result)) {
      $data[]=$row;
    }
    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {
        echo json_encode($data); die;
    }

    if(!empty($_POST['name'])){
        $name = $_POST['name'];//标题
        $pid =$_POST['pid'];//类型
        $sql = "insert into `cate` (`name`,`pid`) values('$name',$pid)";
        $result =mysqli_query($link,$sql);
        $rows=mysqli_affected_rows($link);
		    if($rows>0){
				echo '<script>alert("添加成功");location.href="index.php?c=cate&a=list&admin=1"</script>';die;
			}else{
				echo '<script>alert("添加失败");history.go(-1);</script>';die;
			 }
	}



      //视图加载页面
      include (VIEW_LAYER.'/admin/layout.html');
?>